<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <link rel="stylesheet" href="css/public.css" type="text/css">
    <link rel="stylesheet" href="css/login.css">
</head>
<body>
    <div class="header">
        <div class="header_all">
                <div class="header_left"><img src="image/logo.png" alt="" srcset=""></div>
                <div class="header_right">
                    <a href="index.html">寺库首页</a>
                    <a href="#">收藏寺库</a>
                    <a href="#">寺库APP</a>
                </div>
        </div>    
    </div>
    <div class="center">
        <div class="center_all">
            <div class="center_left"><img src="image/left.jpg" alt=""></div>
            <div class="center_right">
                <div class="center_right_reg">
                    <div class="center_right_regs">
                        <div class="top"><a href="javascript:;" id="sm">扫码登录</a><a href="javascript:;" id="mm">密码登录</a></div>
                        <div id="qr"> 
                            <div class="pic"><img src="image/login_03.jpg"></div>
                            <div class="ope">打开&ensp;<a href="#">寺库APP</a>&ensp;扫一扫登录</div>
                        </div>
                        <div id="pd">
                                <div class="error pngfix" style="display: none;" id="error_msg">用户名或密码不正确</div>
                            <div class="uname">
                                <input type="text" id="uname" placeholder="请输入手机号或邮箱"/>
                            </div>
                            <div class="upwd">
                                <input type="password" placeholder="密码" id="upwd"/>
                            </div>
                            <span class="yz">验证码：</span>
                            <div class="code">
                                <input type="text" value="" placeholder="输入验证码" class="input-val"/>
                                <canvas id="canvas"></canvas>
                               <input type="checkbox" id="check"><label for="check">记住账号</label>
                                <div class="btn">提交</div>
                            </div>
                            
                        </div>
                        <div class="tem"><p>使用合作账户网站登录</p></div>
                        <div class="tec"><img src="image/login_10.jpg"><a href="javascript:;"> QQ </a><img src="image/login_07.jpg" ><a href="javascript:;">微信</a></div>
                        <div class="vips">还不是寺库会员？<a href="register.html">免费注册</a><a href="#" class="wj">忘记密码？</a></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="bottom_top">
            <ul>
                
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
            </ul>
            <ul>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
            </ul>
            <ul>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
            </ul>
            <ul>
                <li><a href="#">诗库奢饰品养护</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
                <li><a href="#">新手指南</a></li>
            </ul>
    
           
        </div>
        <div class="bottom_bottom">
            <p>统一社会信用代码：91110102689248179K</p>
            <p><img src="image/ga.png"><a href="#">京公安备11010102001392</a></p>
            <p>京ICP证110119号&nbsp;京ICP备09084709号-3</p>
            <p>IS09001中国质量管理体系认证</p><br>
            <p>COPYRIGHT&COPY;2010-2017北京寺库商贸有限公司&nbsp;版却所有</p><br>
            <a href="#" class="low"><img src="image/1.jpg"></a>
            <a href="#" class="low"><img src="image/2.jpg"></a>
            <a href="#" class="low"><img src="image/3.jpg"></a>
            <a href="#" class="low"><img src="image/4.jpg"></a>
            <a href="#" class="low"><img src="image/5.jpg"></a>
        </div>
    </div>
</body>
</html>

<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/public.js"></script>
<script src="js/cookie.js"></script>

//验证码 网上
<script>
    $(function(){
        var show_num = [];
        draw(show_num);

        $("#canvas").on('click',function(){
            draw(show_num);
        })
        
        var uname = "";
        $(".btn").on('click',function(){
            var val = $(".input-val").val().toLowerCase();
            var num = show_num.join("");
            var uname = $("#uname").val();
            var upwd = $("#upwd").val();
            var username = uname.substring(0,10)
            setCookie("uname",username);
            var url = `http://jx.xuzhixiang.top/ap/api/login.php?username=${uname}&password=${upwd}`;
            // console.log(uname)
            // console.log(url)
            var m = 0;
            $.ajax({
                url:url,
                type:'get',
                success:function (res) {
                    var obj = eval("("+res+")");
                    if(obj.code == 1){
                        //console.log(obj.code)
                        if(val==''){
                          alert('请输入验证码！');
                         }else if(val == num){
                             alert("输入正确");
                             window.location.href = "index.html"
                            $(".input-val").val('');
                         draw(show_num);
                        }else{
                            alert('验证码错误！请重新输入！');
                            $(".input-val").val('');
                            draw(show_num);
                            } 
                    }else{
                        $("#error_msg").css({display:"block"})
                    } 
                },
                error:function (error) {
                    console.log(error);
                }
            })

            
                
        })
    })
  
    function draw(show_num) {
        var canvas_width=$('#canvas').width();
        var canvas_height=$('#canvas').height();
        var canvas = document.getElementById("canvas");//获取到canvas的对象，演员
        var context = canvas.getContext("2d");//获取到canvas画图的环境，演员表演的舞台
        canvas.width = canvas_width;
        canvas.height = canvas_height;
        var sCode = "A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0";
        var aCode = sCode.split(",");
        var aLength = aCode.length;//获取到数组的长度
        
        for (var i = 0; i <= 3; i++) {
            var j = Math.floor(Math.random() * aLength);//获取到随机的索引值
            var deg = Math.random() * 30 * Math.PI / 180;//产生0~30之间的随机弧度
            var txt = aCode[j];//得到随机的一个内容
            show_num[i] = txt.toLowerCase();
            var x = 10 + i * 20;//文字在canvas上的x坐标
            var y = 20 + Math.random() * 8;//文字在canvas上的y坐标
            context.font = "bold 23px 微软雅黑";

            context.translate(x, y);
            context.rotate(deg);

            context.fillStyle = randomColor();
            context.fillText(txt, 0, 0);

            context.rotate(-deg);
            context.translate(-x, -y);
        }
        for (var i = 0; i <= 5; i++) { //验证码上显示线条
            context.strokeStyle = randomColor();
            context.beginPath();
            context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height);
            context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height);
            context.stroke();
        }
        for (var i = 0; i <= 30; i++) { //验证码上显示小点
            context.strokeStyle = randomColor();
            context.beginPath();
            var x = Math.random() * canvas_width;
            var y = Math.random() * canvas_height;
            context.moveTo(x, y);
            context.lineTo(x + 1, y + 1);
            context.stroke();
        }
    }

    function randomColor() {//得到随机的颜色值
        var r = Math.floor(Math.random() * 256);
        var g = Math.floor(Math.random() * 256);
        var b = Math.floor(Math.random() * 256);
        return "rgb(" + r + "," + g + "," + b + ")";
    }
</script>
<script>
    var qr = $id("qr");
    var pd = $id("pd");
    $id("mm").onclick = function(){
        pd.style.display = "block"
        qr.style.display = "none"
        $id("mm").style.color= "#f19108"
        $id("sm").style.color= "black"
    }
    $id("sm").onclick = function(){
        pd.style.display = "none";
        qr.style.display = "block";
        $id("sm").style.color= "#f19108"
        $id("mm").style.color= "black" 
    } 
</script>


